{extend name="common:base" /}
{block name="page_current"}
<div class="fui-page-group statusbar">
    <style>
        #page-address-selector  .fui-radio.fui-radio-danger:before{
            border-width: 2px 2px 0 0;
            height: 0.4rem;
            width: .7rem;
        }
    </style>
    <div class="fui-page  address-selector-page fui-page-current" id="page-address-selector">
        <div class="fui-header">
            <div class="fui-header-left">
                <a class="back"></a>
            </div>
            <div class="title" style="padding-left: 1.5rem">
                <div style="padding:0.4rem ">
                    <form method="post" id="frmSearch">
                    <div class="search-input">
                        <i class="icon icon-search"></i>
                        <input type="text" id="search" name="keywords" placeholder="输入收件人或手机号关键字..." style="border: 0;background: #efefef;" value="">
                    </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="fui-content">
            <div id="noaddress" class="content-empty" style="display:none">
                <!--<i class='icon icon-location'></i>-->
                <!--<br/>您还没有任何收货地址-->
                <img src="__STATIC__/m/imgs/noadd.png" style="width: 6rem;margin-bottom: .5rem;"><br><p style="color: #999;font-size: .75rem">您暂时没有任何收货地址哦！</p>
            </div>
            <div id="addresslist" class="fui-list-group">
            </div>
        </div>
        <div class="fui-navbar">
            <a href="{:url('Member/address_post')}" class="nav-item btn btn-danger external" data-nocache="true"><i class="icon icon-add"></i> 新增地址</a>
        </div>
        <script id="tpl_address_item" type="text/html">
            {{#  layui.each(d.list, function(index, item){ }}
            <div class="fui-list address-item" data-isdefault="{{ item.is_default }}" data-addressid="{{ item.id }}">
                <div class="fui-list-media">
                    <input type="radio" name="selected" class="fui-radio fui-radio-danger" {{#  if(now_select > 0 && now_select == item.id){ }}checked{{#  } }}{{#  if(now_select < 1 && item.is_default > 0){ }}checked{{#  } }}/>
                </div>
                <div class="fui-list-inner" onclick="selectAddress({{ item.id }});" addressid="{{ item.id }}">
                    <div class="title"><span class='realname'>{{ item.realname }}</span> <span class='mobile'>{{ item.mobile }}</span></div>
                    <div class="text">
                        <span class='address'>{{#  if(item.is_default){ }}<span class="tacitlyapprove">默认</span>{{#  } }} <span class="cun">{{ item.address }}</span></span>
                    </div>
                </div>
                <a href="{{ item.edit_url }}" class="external" data-nocache="true">
                    <div class="fui-list-angle">
                        <i class='icon icon-edit'></i>
                    </div>
                </a>
            </div>
            {{#  }); }}
        </script>
    </div>
    <script src="__STATIC__/layer/layui.js"></script>
    <script src="__STATIC__/layer/laytpl.js"></script>
    <script src="https://cdn.bootcss.com/store.js/1.3.20/store.min.js"></script>
    <script>
        var now_select = {$nowSelect};
        function getAddressList() {
            core.json("{:url('m/Member/get_address_list')}",{keyword:$('#search').val()},function (json) {
                if(json.code){
                    var view = document.getElementById('addresslist');
                    if(json.data.length > 0){
                        $('#noaddress').hide(0);
                        var getTpl = $('#tpl_address_item').text();
                        layui.laytpl(getTpl).render({list:json.data}, function(html){
                            view.innerHTML = html;
                        });
                    }
                    else{
                        view.innerHTML = '';
                        $('#noaddress').show(0);
                    }
                }
            },true,false);
        }
        getAddressList();
        $(function () {
            $("#frmSearch").on("submit", function(e){
                getAddressList();

                return false;
            });
        })
        function selectAddress(_id) {
            var $select = $('[addressid="' + _id + '"]');
            var address = {
                id : _id
                ,realname : $select.find('.realname').html()
                ,mobile : $select.find('.mobile').html()
                ,address : $select.find('.address .cun').html()
            };
            console.log(address);
            store.set('select_address', address);
            history.back();
        }
    </script>
</div>
{/block}

{block name="script"}{/block}